package com.bfs.anasit.model;


import com.bfs.anasit.model.embeddable.Name;
import com.bfs.core.model.BaseModel;

import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Model;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.*;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: lukman
 * Date: 6/11/11
 * Time: 7:49 PM
 * To change this template use File | Settings | File Templates.
 */

@Entity
@Named
@Dependent
public class Patient extends BaseModel {

    private static final long serialVersionUID = 1L;

    private Long patientId;

    @Inject
    private Name name;
    private Long age;

    private Set<Record> records;

    public Patient() {
    }

    public Patient(Long patientId) {
        this.patientId = patientId;
    }

    @Id
    @GeneratedValue
    public Long getPatientId() {
        return patientId;
    }

    public Patient(String firstName, String lastName) {
        name.setFirstName(firstName);
        name.setLastName(lastName);
    }

    public void setPatientId(Long patientId) {
        this.patientId = patientId;
    }

    public Long getAge() {
        return age;
    }

    public void setAge(Long age) {
        this.age = age;
    }

    @OneToMany(mappedBy = "patient", cascade = CascadeType.ALL)
    public Set<Record> getRecords() {
        return records;
    }

    public void setRecords(Set<Record> records) {
        this.records = records;
    }

    public Name getName() {
        return name;
    }

    public void setName(Name name) {
        this.name = name;
    }


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (patientId != null ? patientId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - Should be implemented properly
        if (!(object instanceof Patient)) {
            return false;
        }
        Patient other = (Patient) object;
        if ((this.patientId == null && other.patientId != null) || (this.patientId != null && !this.patientId.equals(other.patientId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bfs.anasit.model.Patient[ patientId =" + patientId + " ]";
    }

}

